package com.ptszyxx.popose.module.base.user;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ActivityUserResultBinding;
import com.ptszyxx.popose.module.base.user.vm.UserResultVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.http.data.entity.user.UserResult;
import java.util.List;

/**
 * 完善用户信息
 */
public class UserResultFragment extends BaseFragment<ActivityUserResultBinding, UserResultVM> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.activity_user_result;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public UserResultVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(UserResultVM.class);
    }

    @Override
    public void initView() {
        super.initView();
        binding.tvContent.setText(getResources().getString(R.string.app_name) + "是高品质真实社交。");
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.requestUser();
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.uc.onTagEvent.observe(this, o -> setTagUI());
    }

    private void setTagUI() {
        UserResult userEntity = viewModel.userEntity.get();
        if (userEntity == null){
            return;
        }
        List<String> list = userEntity.getBiaoqianList();
        binding.flowlayout.setData(list, null);
    }

}